// pages/publish/publish.js
Page({

  data: {
    adress: '请输入你的地址',
    success: false// 默认页面一打开是false
  },
  staticData: {
    type: 'seil'
  },
  handelAdressClick() {
    wx.chooseLocation({
      success: this.handleChooseLocationSucc.bind(this)
    })
  },
  handleChooseLocationSucc(res) {
    console.log(res)
    this.setData({
      adress: res.address
    });
    Object.assign(this.staticData, {//将经度、纬度的数据存到staticData里
      latitude: res.latitude,
      longitude: res.longitude
    })
  },
  handleTypeChange(e) {
    //console.log(e.detail.value)
    this.staticData.type = e.detail.value
    // console.log(this.staticData)
    // console.log(this.data)
  },
  handleMessageContact(e) {
    console.log(e.detail.value)
    this.staticData.message = e.detail.value
  },
  handleChangeContact(e) {
    this.staticData.contact = e.detail.value
  },
  handleSubmit() {
    var that = this
    //console.log('asd')
    if (this.data.adress === '点击选择 要勾选奥' || !this.data.adress) {
      //console.log('请填写地址')
      wx.showToast({
        title: '请填写地址',
        icon: 'loading',
        duration: 2000
      })
      return
    }
    if (!this.staticData.message) {
      //console.log('请填写说明信息')
      wx.showToast({
        title: '请填写说明信息',
        icon: 'loading',
        duration: 2000
      })
      return
    }
    if (!this.staticData.contact) {
      //console.log('请填写联系方式')
      wx.showToast({
        title: '请填写联系方式',
        icon: 'loading',
        duration: 2000
      })
      return
    }
    wx.request({
      url: 'http://t.yushu.im/v2/movie/top250',
      data: {
        adress: this.data.adress,
        latitude: this.staticData.latitude,
        longitude: this.staticData.longitude,
        message: this.staticData.message,
        contact: this.staticData.contact,
        type: this.staticData.contact
      },
      method: "GET",
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: function (res) {
        //console.log(res.data)
        if (res.data) {
          that.setData({
            success: true
          })
        }
      }
    })
  },
  handleBackTap() {
    //console.log('aaa')
    wx.navigateTo({
      url: '../index/index'
    })
  },
  onShareAppMessage: function () {

  }
})